﻿#ifndef SOCKETOBJECT_H
#define SOCKETOBJECT_H

#include <QGraphicsItem>

class SocketObject : public QGraphicsItem
{
public:
    enum {Type = UserType+1 };
    explicit SocketObject(QGraphicsItem *parent , QGraphicsTextItem *carNumberItem , QString *carIP);
    ~SocketObject();

    int type() const override { return Type; }

    //提供对外接口，实现对值的修改,其实这里实现不是很好，其不需要多次改变，在构造函数中实现就好
    void SocketID(const QString &SocketID){SocketName = SocketID;}
    void socketNumber(const QString &SocketNumber) {msocketNumber = SocketNumber;}

    QString getcarNumber() const {return  carNumberItem->toPlainText(); }
    QString getSocketName() const {return  SocketName;}
    QString getsocketNumber() const {return  msocketNumber;}
    QString getcarIP() const {return *carIP; } 
    bool getIsATOrigin() const {return isAtOringin;}
    bool getIsMoving() const {return  isMoving;}
    bool getIsConnected() const{return  isConnected;}

    void mSCtoC0(){ mysocketcolor = Color_0;}//原点位，未自检
    void mSCtoC1(){ mysocketcolor = Color_1 ; isAtOringin = true; isMoving = false ; isConnected = false;}//原点位，自检正常
    void mSCtoC2(){ mysocketcolor = Color_2 ; isAtOringin = false; isMoving = true ; isConnected = false;}////动作中
    void mSCtoC3(){ mysocketcolor = Color_3 ; isAtOringin = false; isMoving = false ; isConnected = true;}//压紧到位

protected:
    QRectF boundingRect() const override;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;

private:
    QGraphicsTextItem *carNumberItem;
    QString SocketName;
    QColor mysocketcolor;
    QColor Color_0;
    QColor Color_1;
    QColor Color_2;
    QColor Color_3;
    QString msocketNumber;
    QString *carIP;

    bool isAtOringin;
    bool isMoving;
    bool isConnected;
};

#endif // SOCKETOBJECT_H
